package com.archie.zhufengfm.entity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by Archie on 2015/10/23.
 */
public class AlbumDetails implements Parsable {

    private Album album;

    private List<Track> tracks;

    public Album getAlbum() {
        return album;
    }

    public List<Track> getTracks() {
        return tracks;
    }

    @Override
    public void parseJSON(JSONObject json) throws JSONException {

        if (json != null) {

            // 获取专辑概述
            JSONObject albumJSON = json.getJSONObject("album");

            Album album = new Album();

            album.parseJSON(albumJSON);

            this.album = album;

            // 获取曲目集合
            JSONObject obj = json.getJSONObject("tracks");
            JSONArray array = obj.getJSONArray("list");

            int len = array.length();

            tracks = new LinkedList<>();

            Track track = null;

            for (int i = 0; i < len; i++) {

                JSONObject trackJOSN = array.getJSONObject(i);

                track = new Track();

                track.parseJSON(trackJOSN);

                tracks.add(track);

            }
        }

    }
}
